package com.hlf.modules.sys.controller;

import com.hlf.common.utils.ReturnResult;
import com.hlf.modules.merchant.bank.entity.BranchBank;
import com.hlf.modules.merchant.bank.service.BankCardBinService;
import com.hlf.modules.merchant.bank.service.BranchBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 银行卡Controller
 *
 * @author pan
 * @date 2017-10-24
 */
@Controller
@RequestMapping("bank")
public class BankController {

    @Autowired
    private BranchBankService branchBankService;
    @Autowired
    private BankCardBinService bankCardBinService;

    @ResponseBody
    @RequestMapping("/selectByProviceAndCity")
    public List<BranchBank> selectByProviceAndCity(String bankCardNo, BranchBank branchBank) {
        String bankOrgCode = bankCardBinService.getBankOrgCodeByCardNo(bankCardNo);
        branchBank.setBankOrgCode(bankOrgCode);

        List<BranchBank> branchBanks = branchBankService.selectByProviceAndCity(branchBank);

        return branchBankService.selectByProviceAndCity(branchBank);
    }

    @ResponseBody
    @RequestMapping("/getBankOrgCode")
    public String getBankOrgCode(String bankCardNo) {
        return bankCardBinService.getBankOrgCodeByCardNo(bankCardNo);
    }

    @ResponseBody
    @RequestMapping("/selectById")
    public ReturnResult selectById(String id) {
        if (StringUtils.isEmpty(id)){
            return ReturnResult.error();
        }
        BranchBank branchBank = branchBankService.selectById(Integer.parseInt(id));
        return ReturnResult.ok().put("result",branchBank);
    }
}
